﻿#ifndef WINSPEAKERRECORD_H
#define WINSPEAKERRECORD_H

#include "WinMediaDevice.h"
#include <Audioclient.h>
#include <Functiondiscoverykeys_devpkey.h>
#include <mmdeviceapi.h>
#include <avrt.h>

class WinSpeakerRecord : public WinMediaDevice
{
    Q_OBJECT
public:
    explicit WinSpeakerRecord(QObject *parent = nullptr);
    virtual ~WinSpeakerRecord();

public:
    virtual IMMDevice *getDevice() override;

    virtual bool init() override;
    virtual bool capture() override;

public slots:
    virtual void run();

private:
    HANDLE m_hEventStop;
    HANDLE m_hEventStarted;

    IAudioClient *pAudioClient = NULL;
    WAVEFORMATEX *pwfx = NULL;
    REFERENCE_TIME hnsDefaultDevicePeriod = 0;
    HANDLE hTimerWakeUp = NULL;
    IAudioCaptureClient *pAudioCaptureClient = NULL;
    DWORD nTaskIndex = 0;
    HANDLE hTask = NULL;
    BOOL bStarted = FALSE;
};

#endif // WINSPEAKERRECORD_H
